package wp.wf.com.myapplication.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import java.util.List;

import wp.wf.com.myapplication.bean.MyViewHolder;

/**
 * Created by KF on 2016/4/25.
 */
public abstract class RecycleBaseAdapter<T> extends RecyclerView.Adapter<MyViewHolder> {
    private Context context;
    private List<T> list;
    private int layoutId;

    public RecycleBaseAdapter(Context context, List<T> list, int layoutId) {
        this.context = context;
        this.list = list;
        this.layoutId = layoutId;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return MyViewHolder.getViewHolder(layoutId, context);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        onBindView(holder, holder.getLayoutPosition(), list.get(holder.getLayoutPosition()));
    }


    @Override
    public int getItemCount() {
        return list.size();
    }

    public abstract void onBindView(MyViewHolder holder, int position, T t);
}
